package com.jxk.jsonproject.controller;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jxk.jsonproject.entity.User;
import org.apache.catalina.mapper.Mapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {
    @PostMapping("/testjson")
    public List<User> getUser(@RequestBody List<User>users){
        users.forEach(System.out::println);
        ObjectMapper mapper=new ObjectMapper();
        String s = null;
        try {
            s = mapper.writeValueAsString(users);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println(s);
        try {
            List<User> users1 = mapper.readValue(s, new TypeReference<List<User>>() {});
            System.out.println(users1);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return  users;
    }
}
